package com.sfh.dog.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.sfh.dog.DogApplication;
import com.sfh.dog.R;
import com.sfh.dog.entity.GiftEntity;
import com.sfh.dog.http.APIConfig;

/**
 * 礼物显示
 * 
 * @author SunFeihu 孙飞虎
 * @version [版本号2014-3-28]
 */
public class DogGiftAdapter extends BaseAdapter
{
	private List<GiftEntity> mEntities;

	public void setEntities(List<GiftEntity> data)
	{
		this.mEntities.clear();
		if (null != data && data.size() > 0)
		{
			this.mEntities.addAll(data);
			notifyDataSetChanged();
		}

	}

	private LayoutInflater mInflater;

	public DogGiftAdapter(Context context)
	{
		super();
		this.mInflater = LayoutInflater.from(context);
		this.mEntities = new ArrayList<GiftEntity>();

	}

	@Override
	public int getCount()
	{
		return mEntities.size();
	}

	@Override
	public Object getItem(int arg0)
	{
		return mEntities.get(arg0);
	}

	@Override
	public long getItemId(int arg0)
	{
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2)
	{
		HondlerView mHondlerView = null;
		if (arg1 == null)
		{
			arg1 = mInflater.inflate(R.layout.dog_gift_item, arg2, false);
			mHondlerView = new HondlerView();
			mHondlerView.ivPhoto = (ImageView) arg1.findViewById(R.id.ivPhoto);
			arg1.setTag(mHondlerView);
		}
		mHondlerView = (HondlerView)arg1.getTag();
		ImageLoader.getInstance().displayImage(
				APIConfig.getGiftURL(mEntities.get(arg0).pathID),
				mHondlerView.ivPhoto, DogApplication.options);
		return arg1;
	}

	static class HondlerView
	{
		public ImageView ivPhoto;

	}
}
